package edu.codink.xq.sys.controller;

import java.util.List;

import org.springframework.stereotype.Service;

import edu.codink.common.base.BasicService;
import edu.codink.common.base.Page;
import edu.codink.xq.center.entity.Userinfo;

@Service
public class UserHbmServiceImpl extends BasicService implements UserHbmService
{

	@Override
	public List<Userinfo> list(Userinfo param, Page page)
	{
		return super.selectByPageHql("select p from Userinfo p",page);
	}

	@Override
	public long count(Userinfo param)
	{
		return super.hqlCount("");
	}

	@Override
	public void save(Userinfo user)
	{
		super.save(user);
	}

	@Override
	public long validate(String name)
	{
		return super.hqlCount( "select count(s) from Userinfo s where userName=?", name);
	}

	@Override
	public Userinfo query(Integer id)
	{
		List<Userinfo> list = super.selectAllByHql( "select p from Userinfo p where ygbh=?", id);
		if (list != null && !list.isEmpty())
		{
			return list.get(0);
		}
		return null;
	}

	@Override
	public Integer update(Userinfo user)
	{
		boolean flag = super.update(user);
		if (flag)
		{
			return 1;
		}
		return 0;
	}

	@Override
	public void deleteUserRoles(Integer userId)
	{
		super.delByHqlQuery("delete from RefUserRule where userId = ?",
				new Object[] { userId });
	}

	@Override
	public List<Integer> queryUserRules(Integer userId)
	{
		return super.selectAllByHql(
				"select ruleId from RefUserRule p where userId = ?", userId);
	}

	@Override
	public Integer deleteUser(Integer userId)
	{
		boolean flag = super.delById(Userinfo.class, userId);
		if (flag)
		{
			return 1;
		}
		return 0;
	}
}
